<?php
/**
 * Created by PhpStorm.
 * User: mojie126
 * Date: 2017/5/25 0025
 * Time: 下午 13:45
 */

namespace app\index\widget;

use app\index\controller\Base;
use app\index\model\Users;
use think\Controller;

class Widget extends Controller
{
	public function header()
	{
		$menu = db("menu")->where("display", "0")->order("sort", "DESC")->select();
		$tmp = [];
		foreach ($menu as $k => $v) {
			$tmp[$v['id']] = $v;
		}

		//无限分类
		$menu = function ($items) {
			foreach ($items as $item)
				$items[$item['pid']]['son'][$item['id']] = &$items[$item['id']];

			return isset($items[0]['son']) ? $items[0]['son'] : array();
		};
		//无限分类

		$userinfo = Users::getUserInfo(session("uid"));
		$this->assign("u", $userinfo);
		$this->assign("menu", $menu($tmp));
		$this->assign("AppName", APP_NAME);
		$access = new Base();
		$access->getAccess("/backend");

		return $this->fetch("Base/Header");
	}

	public function footer()
	{
		$this->assign("time", time());

		return $this->fetch("Base/Footer");
	}

	public function nheader()
	{
		$this->assign("AppName", APP_NAME);

		return $this->fetch("Base/nHeader");
	}

	public function nfooter()
	{
		$this->assign("time", time());

		return $this->fetch("Base/nFooter");
	}
}